﻿
namespace Pibby.Core.Tests.Stubs
{
    using System;
    using Pibby.Core.Views;
	using Pibby.Core.ViewModels;
    using Pibby.Core.IO;

	public class PortableMediaStateView : IPortableMediaView
	{
		public bool ShowDeviceCalled;
		public bool RefreshDeviceCalled;
		public string DeviceName;
		public bool DeviceConnected;
		
		public int TotalItemsToTransfer;
		public int TotalItemsTransferred;
		public bool TransferCompleteCalled;

		#region IPortableMediaStateView

		public event EventHandler<PortableMediaSettingsEventArgs> PortableMediaSettingsChanged;

		public event EventHandler<RemovableDriveEventArgs> RemovableDeviceArrived;
		public event EventHandler<RemovableDriveEventArgs> RemovableDeviceRemoved;

		public event EventHandler<TransferCommandEventArgs> TransferContent;

		public event EventHandler EjectDevice;

		public void ShowDeviceStatus(PortableMediaViewModel e)
		{
			ShowDeviceCalled = true;
			DeviceName = e.VolumeLabel;
			DeviceConnected = e.Connected;
		}

		public void RefreshDeviceStatus(PortableMediaViewModel e)
		{
			RefreshDeviceCalled = true;
			DeviceName = e.VolumeLabel;
			DeviceConnected = e.Connected;
		}

		public void ReportError(string message)
		{
		}

		#endregion IPortableMediaStateView

		public void SimulateMediaSettingsChanged(bool enabled, string friendlyName,
												string volumeName, string folder, OrganizationOption splitFolders, EjectOption autoEject, TransferOption autoTransfer)
		{
			if (this.PortableMediaSettingsChanged != null)
				this.PortableMediaSettingsChanged(this, new PortableMediaSettingsEventArgs(enabled, friendlyName,
												volumeName, folder, splitFolders, autoEject, autoTransfer));
		}

		public void SimulateDriveArrived(string driveName, string volumeName)
		{
			this.RefreshDeviceCalled = false;

			if (this.RemovableDeviceArrived != null)
                this.RemovableDeviceArrived(this, new RemovableDriveEventArgs(driveName, volumeName, RemovableDriveStatus.Connected));
		}

		public void SimulateDriveRemoved(string driveName, string volumeName)
		{
			this.RefreshDeviceCalled = false;

			if (this.RemovableDeviceRemoved != null)
				this.RemovableDeviceRemoved(this, new RemovableDriveEventArgs(driveName, volumeName, RemovableDriveStatus.Disconnected));
		}

		public void SimulateTransferContent(bool deleteFilesAfterTransfer)
		{
			if (this.TransferContent != null)
				this.TransferContent(this, new TransferCommandEventArgs(deleteFilesAfterTransfer));
		}

		public void SimulateEjectButton()
		{
			if (this.EjectDevice != null)
				this.EjectDevice(this, EventArgs.Empty);
		}
		
		public void TransferStarting(int itemsToTransfer)
		{
			TransferCompleteCalled = false;
			TotalItemsToTransfer = itemsToTransfer;
			TotalItemsTransferred = 0;
		}

		public void TransferProgress(int item)
		{
			++TotalItemsTransferred;
		}

		public void TransferFinished()
		{
			TransferCompleteCalled = true;
		}

	}
}
